﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using CSF.Security.Data;

namespace CSF.Security.BLL
{
    public class PermissionTreeNode
    {
        private Permission _permission;

        public PermissionTreeNode(Permission permission)
        {
            _permission = permission;
        }

        public Permission Permission
        {
            get
            {
                return _permission;
            }
        }

        private int[] _roles = null;

        public int[] Roles
        {
            get
            {
                if (_roles == null)
                {
                    RolePermissionBLL bll = new RolePermissionBLL();
                    var list = bll.GetRoleIdsByPermission(Permission.Id);
                    if (list != null)
                    {
                        _roles = list.ToArray();
                    }
                }
                return _roles;
            }
        }

        private Collection<PermissionTreeNode> _children = new Collection<PermissionTreeNode>();

        public Collection<PermissionTreeNode> Children
        {
            get
            {
                return _children;
            }
        }
    }
}
